package hu.gbalage.owlforms.internal.derived;

import java.net.URI;

import hu.gbalage.owlforms.api.Field;
import hu.gbalage.owlforms.api.data.FormData;

public class EltartottakCalc implements IDerivedCalculator {

	public static final String base = "http://owlforms.gbalage.hu/example/eltartottak.owl#";
	
	public static final String[] props = new String[]{
		"nappalis",
		"levelezo",
		"kozepiskolas",
		"altalanosiskolas",
		"szakkepesites",
		"fogyatekos"
	};
	
	public static final int[] values = new int[]{
		7,
		3,
		5,
		3,
		6,
		15
	};
	
	int getValue(FormData on, String what){
		Field field = on.getForm().getField(URI.create(base+what));
		if (field == null){
			System.err.println("Field is null: "+base+what);
		}
		String value = on.getData(field).listValues().get(0).asPrimitiveValue().getValue();
		try{
			return Integer.parseInt(value);
		}catch(NumberFormatException e){
			e.printStackTrace();
			return 0;
		}
	}
	
	public String calculate(FormData on, Field field) {
		
		int osszeg = 0;
		
		for(int i = 0;i<values.length;i++)
			osszeg += getValue(on, props[i])*values[i];
		
		return osszeg+"";
	}
	
}
